package com.kitty.game.task.service.taskHandler;

import com.kitty.game.pet.message.RespGhostPetUpgradeSucc;
import com.kitty.game.pet.model.Pet;
import com.kitty.game.player.model.PlayerExtendBox;
import com.kitty.game.role.model.Role;
import com.kitty.game.equip.model.RoleEquip;
import com.kitty.game.fight.bean.Fight;
import com.kitty.game.config.NPC;
import com.kitty.game.config.TalkSet;
import com.kitty.game.config.TaskSet;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.enter.FiedValue;
import com.kitty.game.equip.message.RespNotifyMiscEx;
import com.kitty.game.equip.service.EquipService;
import com.kitty.game.fight.factory.FightFactory;
import com.kitty.game.npc.service.NewNpcService;
import com.kitty.game.pet.PetDataPool;
import com.kitty.game.pet.bean.PetObject;
import com.kitty.game.pet.message.RespPetUpgradePreInfo;
import com.kitty.game.pet.message.RespPetUpgradeSucc;
import com.kitty.game.pet.message.RespSubmitPet;
import com.kitty.game.rank.model.monitor.PetAttribMonitor;
import com.kitty.game.talk.service.TalkService;
import com.kitty.game.task.TaskDataPool;
import com.kitty.game.task.message.vo.TaskInfo;
import com.kitty.game.task.model.product.TaskType;
import com.kitty.game.task.model.product.targetparam.FightWinTargetParam;
import com.kitty.game.team.message.RespMsg;
import com.kitty.game.utils.Const;
import com.kitty.listener.event.FightEndEvent;
import com.kitty.mina.message.MessagePusher;
import com.kitty.game.team.service.TeamService;
import org.nutz.lang.util.NutMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**宠物飞升处理类*/
@Component
public class PetFlyTaskHandler extends TaskHandler {
    @Autowired
    TeamService teamService;

    /**可飞升的最小等级*/
    private static final int MIN_LEVEL_FLY = 110;
    /**可飞升的最小亲密度*/
    private static final int MIN_INTIMACY_FLY = 30000;

    private static final int STAGE_1_TASKID = 115;
    private static final int STAGE_2_TASKID = 116;
    private static final int STAGE_3_TASKID = 117;
    private static final int GHOST_1_TASKID = 22517;

    private static final int ACCPET_TALKID = 1235;
    private static final int FAIL_TALKID = 1254;
    private static final int FLY_TALKID = 1265;
    private static final int FLY_GHOST_TALKID = 1296;

    /**宠物飞升战斗最大战斗回合数*/
    private static final int MAX_FIGHT_ROUND = 50;

    /**飞升时需要消耗的道具*/
    private static Map<String, Integer> flyUseItems = new HashMap<>();

    private static final String NO_CAN_FLY_PET = "你身上没有满足飞升条件的宠物（等级>=#R110级#n且未飞升过的宠物），就不要来凑热闹了。[离开]";
    private static final String WAIT_TIME = "你刚才已经放弃宠物飞升任务，还是休息一阵再来吧。[离开]";
    private static final String ACCEPT_PET_FLY_TASK_SUC_TIP = "你成功领取了宠物飞升任务。";
    private static final String FIGHT_FAIL_TIP = "本场战斗若宠物死亡则战斗失败。";
    private static final String FLYING_PET_NOT_FIGHT = "先把#Y{0}#n设为参战状态再来找我。[离开]";
    private static final String COUNT_NOT_ENOUGH = "{0}数量不足！";
    private static final String INTIMACY_NOT_ENOUGH = "宠物亲密达到#R{0}#n才可以进行飞升。";
    private static final String HAS_FLYED = "#Y{0}#n已经飞升了。";
    private static final String LEVEL_NOT_ENOUGH = "#Y{0}#n等级不足{1}级。";

    @PostConstruct
    public void init() {
        flyUseItems.put("2阶骑宠灵魄", 3);
        flyUseItems.put("驯兽诀", 1);
        flyUseItems.put("萦香丸", 20);
        flyUseItems.put("聚灵丹", 20);
    }

    @Override
    public TaskType getTaskType() {
        return TaskType.PET_FLY;
    }
    /**选择宠物飞升*/
    public void chooseGhostFly(Role role, NPC npc,int type) {
        TaskSet doingTaskSet = getTaskSetByType(role);
        if (doingTaskSet != null) {
            if(doingTaskSet.getId() == GHOST_1_TASKID){
                openGhostPetFly(role, npc);
            }else{
                MessagePusher.pushMessage(role, new RespNotifyMiscEx("你身上还有未完成的宠物飞升任务，请先完成任务再来！"));
            }
            return ;
        }

        String check = checkFly(role,type);
        if (check != null) {
            SpringUtils.getNpcService().sendNpcContent(role, npc, check);
            return ;
        }
        /**显示选择飞升宠物*/
        RespSubmitPet respSubmitPet = new RespSubmitPet();
        /**临时保存提交宠物类型*/

        role.pushTempCache(Const.SUBMIT_PET_TYPE, Const.SUBMIT_PET_TYPE_FEISHENG_GHOST);
        respSubmitPet.setType(Const.SUBMIT_PET_TYPE_FEISHENG_GHOST);
        MessagePusher.pushMessage(role, respSubmitPet);
    }
    /**选择宠物飞升*/
    public void chooseFly(Role role, NPC npc,int type) {
        TaskSet doingTaskSet = getTaskSetByType(role);
        if (doingTaskSet != null) {
            if(doingTaskSet.getId() == STAGE_2_TASKID){
                SpringUtils.getBean(NewNpcService.class).popTaskTalk(role, npc, STAGE_2_TASKID);
            }else if(doingTaskSet.getId() == STAGE_3_TASKID){
                openPetFly(role, npc);
            }else{
                MessagePusher.pushMessage(role, new RespNotifyMiscEx("你身上还有未完成的宠物飞升任务，请先完成任务再来！"));
            }
            return ;
        }

        String check = checkFly(role,type);
        if (check != null) {
            SpringUtils.getNpcService().sendNpcContent(role, npc, check);
            return ;
        }
        /**显示选择飞升宠物*/
        RespSubmitPet respSubmitPet = new RespSubmitPet();
        /**临时保存提交宠物类型*/
        if(type == 2){
            role.pushTempCache(Const.SUBMIT_PET_TYPE, Const.SUBMIT_PET_TYPE_FEISHENG);
            respSubmitPet.setType(Const.SUBMIT_PET_TYPE_FEISHENG);
        }else{
            role.pushTempCache(Const.SUBMIT_PET_TYPE, Const.SUBMIT_PET_TYPE_FEISHENG_GHOST);
            respSubmitPet.setType(Const.SUBMIT_PET_TYPE_FEISHENG_GHOST);
        }
        MessagePusher.pushMessage(role, respSubmitPet);
    }
    /**飞升成功*/
    public void openGhostPetFly(Role role, NPC npc) {
        EquipService equipService = SpringUtils.getEquipService();
        /**检测消耗道具是否足够*/
//        for (Map.Entry<String, Integer> entry : flyUseItems.entrySet()) {
//            int count = equipService.getCount(entry.getKey(), true, role);
//            if (count < entry.getValue()) {
//                MessagePusher.pushMessage(role, new RespMsg(MessageFormat.format(COUNT_NOT_ENOUGH, entry.getKey())));
//                return ;
//            }
//        }
        //宠物飞升扣除10积分
//        SpringUtils.getRoleService().substractChargeScore(role,10);
//        MessagePusher.pushMessage(role,new RespNotifyMiscEx("扣除积分10点"));
        /**足够时删除道具*/
//        for (Map.Entry<String, Integer> entry : flyUseItems.entrySet()) {
//            /**2阶骑宠灵魄优先删除传进来位置的那些*/
//            if (entry.getKey().equals("2阶骑宠灵魄")) {
//                int count = entry.getValue();
//                String[] posArray = posString.split(",");
//                if (posArray != null) {
//                    for (String posStr : posArray) {
//                        int pos = Integer.parseInt(posStr);
//                        RoleEquip roleEquip = SpringUtils.getEquipService().getRoleEquipByPos(role, pos);
//                        /**不是2阶骑宠灵魄时跳过*/
//                        if (roleEquip == null || !roleEquip.getName().equals(entry.getKey())) {continue;}
//
//                        int delCount = equipService.delEquipNum(role, roleEquip, 1);
//                        count -= delCount;
//                    }
//                }
//                /**删除剩余数量的*/
//                if (count > 0) {
//                    equipService.delRoloEquip(entry.getKey(), count, true, role);
//                }
//
//                continue;
//            }
//
//            equipService.delRoloEquip(entry.getKey(), entry.getValue(), true, role);
//        }


        /**开始进行飞升*/
        Pet pet = SpringUtils.getPetService().getPetById((Integer)role.getExtendBox().getParams().get("flying_pet_id"), role);
        pet.setFly((byte) 1);
        PetAttribMonitor petAttribMonitor = new PetAttribMonitor(role, pet);

        List<FiedValue> beforeFields = getFields(pet);

        /**设置成长值*/
        PetObject petObject = PetDataPool.getPetObject(pet.getName());
        int lifeValue = petObject.getPerFlyUpgradeAddValue(pet.getLifeEffect(), "life");
        int manaValue = petObject.getPerFlyUpgradeAddValue(pet.getManaEffect(), "mana");
        int speedValue = petObject.getPerFlyUpgradeAddValue(pet.getSpeedEffect(), "speed");
        int magValue = petObject.getPerFlyUpgradeAddValue(pet.getMagEffect(), "mag");
        int phyValue = petObject.getPerFlyUpgradeAddValue(pet.getPhyEffect(), "phy");
        NutMap flyEffect = pet.getFlyEffect();
        flyEffect.setv("phy", phyValue);
        flyEffect.setv("mag", magValue);
        flyEffect.setv("life", lifeValue);
        flyEffect.setv("mana", manaValue);
        flyEffect.setv("speed", speedValue);

        removeTempData(role);
        TaskSet taskSet = getTaskSetByType(role);
        doResetTask(role, taskSet);
        doAfterReset(role, taskSet);

        role.save();

        SpringUtils.getPetService().refreshPetInfo(role, pet);

        /**显示对话*/
//        TalkService talkService = SpringUtils.getBean(TalkService.class);
//        TalkSet talkSet = talkService.getTalkSet(FLY_TALKID, role);
//        talkService.popFirstTalk(role, talkSet);

        /**显示飞升成功界面*/
        List<FiedValue> alterFields = getFields(pet);
        RespGhostPetUpgradeSucc respPetUpgradeSucc = new RespGhostPetUpgradeSucc();
        respPetUpgradeSucc.setPetId(pet.getId());
        respPetUpgradeSucc.setBeforeFields(beforeFields);
        respPetUpgradeSucc.setAlterFields(alterFields);
        MessagePusher.pushMessage(role, respPetUpgradeSucc);
        /**先缓存起来，在对话结束时才显示*/
        //role.pushTempCache("pet_fly_success", respPetUpgradeSucc);

        petAttribMonitor.end();

    }
    /**检测能否接取飞升任务*/
    private String checkFly(Role role,int type) {
        if (isWaitGiveUpCD(role)) {
            return WAIT_TIME;
        }

        // TODO 判断是否有满足飞升条件宠物
        /**获得所有可以飞升的宠物*/
        List<Pet> canFlyPets = getCanFlyPets(role,type);
        if (canFlyPets == null || canFlyPets.size() == 0) {
            return NO_CAN_FLY_PET;
        }
        return null;
    }

    /**获得可以飞升的宠物列表*/
    private List<Pet> getCanFlyPets(Role role,int type) {
        List<Pet> petList = SpringUtils.getPetService().getPetList(role,type);
        if (petList == null) {return null;}

        List<Pet> canList = null;
        for (Pet pet : petList) {
            /**等级不足够*/
            if (pet.getLevel() < MIN_LEVEL_FLY) {continue;}

            /**已经飞升*/
            if (pet.isFly()) {continue;}


            if (canList == null) {
                canList = new ArrayList<>();
            }
            canList.add(pet);
        }

        return canList;
    }

    /**确认选择的飞升宠物*/
    public void confirmChooseFlyPet(Role role, Pet pet,int type) {
        String check = checkConfirmChoose(role, pet);
        if (check != null) {
            MessagePusher.pushMessage(role, new RespMsg(check));
            return ;
        }


        if (role.getExtendBox() == null) {
            role.setExtendBox(new PlayerExtendBox());
        }
        /**设置正在飞升的宠物*/
        /**当前正在进行引导飞升的宠物*/
        role.getExtendBox().getParams().put("flying_pet_id", pet.getId());

        /**弹出对话*/
        TalkService talkService = SpringUtils.getBean(TalkService.class);
        TalkSet talkSet = new TalkSet();
        TaskSet taskSet = new TaskSet();
        if(type == 2){
            talkSet = talkService.getTalkSet(ACCPET_TALKID, role);
            taskSet = SpringUtils.getTaskService().getTaskSet(STAGE_1_TASKID, role);
        }else if(type == 5){
            talkSet = talkService.getTalkSet(FLY_GHOST_TALKID, role);
            taskSet = SpringUtils.getTaskService().getTaskSet(GHOST_1_TASKID, role);
        }
        talkService.popFirstTalk(role, talkSet);
        acceptTask(role, taskSet);
        teamService.pushMessage(role, new RespNotifyMiscEx(ACCEPT_PET_FLY_TASK_SUC_TIP));
    }

    private String checkConfirmChoose(Role role, Pet pet) {
        if (pet.getIntimacy() < MIN_INTIMACY_FLY) {
            return MessageFormat.format(INTIMACY_NOT_ENOUGH, MIN_INTIMACY_FLY);
        }
        if (pet.isFly()) {
            return MessageFormat.format(HAS_FLYED, pet.getName());
        }
        if (pet.getLevel() < MIN_LEVEL_FLY) {
            return MessageFormat.format(LEVEL_NOT_ENOUGH, pet.getName(), MIN_LEVEL_FLY);
        }

        return null;
    }

    @Override
    public void doFightFail(Role role, FightEndEvent fightEndEvent) {
        super.doFightFail(role, fightEndEvent);

        fail(role, fightEndEvent);
    }

    private void fail(Role role, FightEndEvent fightEndEvent) {
        if (fightEndEvent.getFightType() != Const.fightType_petFly) {return ;}
        /**没有正在飞升宠物*/
        if (role.getExtendBox() == null || role.getExtendBox().getParams().get("flying_pet_id") == null) {return ;}

        TalkService talkService = SpringUtils.getBean(TalkService.class);
        TalkSet talkSet = talkService.getTalkSet(FAIL_TALKID, role);
        talkService.popFirstTalk(role, talkSet);
    }

    @Override
    public TaskInfo getTaskInfo(Role role, TaskSet taskSet) {
        TaskInfo taskInfo = super.getTaskInfo(role, taskSet);
        try{
            /**宠物飞升名字替换*/
            Pet pet = SpringUtils.getPetService().getPetById((Integer) role.getExtendBox().getParams().get("flying_pet_id"), role);
            if (role.getExtendBox() != null && role.getExtendBox().getParams().get("flying_pet_id") != null && pet != null) {
                taskInfo.setTaskZhiyin(taskInfo.getTaskZhiyin().replace("{flying_pet_name}", pet.getName()));
                taskInfo.setTaskInfo(taskInfo.getTaskInfo().replace("{flying_pet_name}", pet.getName()));
            }
            return taskInfo;
        }catch(Exception e){
            return taskInfo;
        }
    }

    /**与米兰请教*/
    public void startFightTask(Role role, NPC npc) {
        if (role.getExtendBox() != null && role.getExtendBox().getParams().get("flying_pet_id") != null && role.getPetBox().getFightPetId() != (Integer) role.getExtendBox().getParams().get("flying_pet_id")) {
            Pet pet = SpringUtils.getPetService().getPetById((Integer) role.getExtendBox().getParams().get("flying_pet_id"), role);
            String msg = MessageFormat.format(FLYING_PET_NOT_FIGHT, pet.getName());
            SpringUtils.getNpcService().sendNpcContent(role, npc, msg);
            return ;
        }

        SpringUtils.getBean(NewNpcService.class).popTaskTalk(role, npc, STAGE_1_TASKID);
    }

    /**开始 宠物升级任务的与武学道宠、物攻道宠、法攻道宠战斗*/
    public Fight startFight(Role role, TaskSet taskSet, FightWinTargetParam fightWinTargetParam) {
        if (role.getExtendBox() != null && (Integer)role.getExtendBox().getParams().get("flying_pet_id") != role.getPetBox().getFightPetId()) {
            Pet pet = SpringUtils.getPetService().getPetById((Integer)role.getExtendBox().getParams().get("flying_pet_id"), role);
            String msg = MessageFormat.format(FLYING_PET_NOT_FIGHT, pet.getName());
            MessagePusher.pushMessage(role, new RespMsg(msg.replace(Const.LEAVE_BUTTON, "")));
            return null;
        }
        byte fightType = Const.fightType_petFly;
        Fight fight = FightFactory.getFightFactory(fightType).create(
                0, role, fightWinTargetParam.getFightTargetType(), taskSet.getId(), fightWinTargetParam.getFightTarget());
        fight.setType(fightType);
        fight.setMaxRound(MAX_FIGHT_ROUND);

        SpringUtils.getTeamService().pushMessage(role, new RespMsg(FIGHT_FAIL_TIP));
        return fight;
    }

    /**打开飞升提交物品界面*/
    public void openPetFly(Role role, NPC npc) {
        RespPetUpgradePreInfo respPetUpgradePreInfo = getRespPetUpgradePreInfo(role);
        if (respPetUpgradePreInfo != null) {
            MessagePusher.pushMessage(role, respPetUpgradePreInfo);
        }
    }

    public RespPetUpgradePreInfo getRespPetUpgradePreInfo(Role role) {
        if (role.getExtendBox() != null && role.getExtendBox().getParams().get("flying_pet_id") != null) {
            RespPetUpgradePreInfo respPetUpgradePreInfo = new RespPetUpgradePreInfo();
            respPetUpgradePreInfo.setPetId((Integer) role.getExtendBox().getParams().get("flying_pet_id"));
            List<FiedValue> fields = new ArrayList<>();
            respPetUpgradePreInfo.setFields(fields);

            /**增加的属性值*/
            Pet pet = SpringUtils.getPetService().getPetById((Integer)role.getExtendBox().getParams().get("flying_pet_id"), role);
            if (pet == null){
                return respPetUpgradePreInfo;
            }
            PetObject petObject = PetDataPool.getPetObject(pet.getName());
            int lifeValue = petObject.getPerFlyUpgradeAddValue(pet.getLifeEffect(), "life");
            int manaValue = petObject.getPerFlyUpgradeAddValue(pet.getManaEffect(), "mana");
            int speedValue = petObject.getPerFlyUpgradeAddValue(pet.getSpeedEffect(), "speed");
            int magValue = petObject.getPerFlyUpgradeAddValue(pet.getMagEffect(), "mag");
            int phyValue = petObject.getPerFlyUpgradeAddValue(pet.getPhyEffect(), "phy");

            fields.add(new FiedValue(104, lifeValue));
            fields.add(new FiedValue(105, manaValue));
            fields.add(new FiedValue(106, speedValue));
            fields.add(new FiedValue(107, magValue));
            fields.add(new FiedValue(108, phyValue));

            return respPetUpgradePreInfo;
        }
        return null;
    }

    /**消耗道具进行飞升操作*/
    public void flyUseItems(Role role, String posString) {
        EquipService equipService = SpringUtils.getEquipService();
        /**检测消耗道具是否足够*/
        for (Map.Entry<String, Integer> entry : flyUseItems.entrySet()) {
            int count = equipService.getCount(entry.getKey(), true, role);
            if (count < entry.getValue()) {
                MessagePusher.pushMessage(role, new RespMsg(MessageFormat.format(COUNT_NOT_ENOUGH, entry.getKey())));
                return ;
            }
        }
        //宠物飞升扣除10积分
//        SpringUtils.getRoleService().substractChargeScore(role,10);
//        MessagePusher.pushMessage(role,new RespNotifyMiscEx("扣除积分10点"));
        /**足够时删除道具*/
        for (Map.Entry<String, Integer> entry : flyUseItems.entrySet()) {
            /**2阶骑宠灵魄优先删除传进来位置的那些*/
            if (entry.getKey().equals("2阶骑宠灵魄")) {
                int count = entry.getValue();
                String[] posArray = posString.split(",");
                if (posArray != null) {
                    for (String posStr : posArray) {
                        int pos = Integer.parseInt(posStr);
                        RoleEquip roleEquip = SpringUtils.getEquipService().getRoleEquipByPos(role, pos);
                        /**不是2阶骑宠灵魄时跳过*/
                        if (roleEquip == null || !roleEquip.getName().equals(entry.getKey())) {continue;}

                        int delCount = equipService.delEquipNum(role, roleEquip, 1);
                        count -= delCount;
                    }
                }
                /**删除剩余数量的*/
                if (count > 0) {
                    equipService.delRoloEquip(entry.getKey(), count, true, role);
                }

                continue;
            }

            equipService.delRoloEquip(entry.getKey(), entry.getValue(), true, role);
        }


        /**开始进行飞升*/
        Pet pet = SpringUtils.getPetService().getPetById((Integer)role.getExtendBox().getParams().get("flying_pet_id"), role);
        pet.setFly((byte) 1);
        PetAttribMonitor petAttribMonitor = new PetAttribMonitor(role, pet);

        List<FiedValue> beforeFields = getFields(pet);

        /**设置成长值*/
        PetObject petObject = PetDataPool.getPetObject(pet.getName());
        int lifeValue = petObject.getPerFlyUpgradeAddValue(pet.getLifeEffect(), "life");
        int manaValue = petObject.getPerFlyUpgradeAddValue(pet.getManaEffect(), "mana");
        int speedValue = petObject.getPerFlyUpgradeAddValue(pet.getSpeedEffect(), "speed");
        int magValue = petObject.getPerFlyUpgradeAddValue(pet.getMagEffect(), "mag");
        int phyValue = petObject.getPerFlyUpgradeAddValue(pet.getPhyEffect(), "phy");
        NutMap flyEffect = pet.getFlyEffect();
        flyEffect.setv("phy", phyValue);
        flyEffect.setv("mag", magValue);
        flyEffect.setv("life", lifeValue);
        flyEffect.setv("mana", manaValue);
        flyEffect.setv("speed", speedValue);

        removeTempData(role);
        TaskSet taskSet = getTaskSetByType(role);
        doResetTask(role, taskSet);
        doAfterReset(role, taskSet);

        role.save();

        SpringUtils.getPetService().refreshPetInfo(role, pet);

        /**显示对话*/
        TalkService talkService = SpringUtils.getBean(TalkService.class);
        TalkSet talkSet = talkService.getTalkSet(FLY_TALKID, role);
        talkService.popFirstTalk(role, talkSet);

        /**显示飞升成功界面*/
        List<FiedValue> alterFields = getFields(pet);
        RespPetUpgradeSucc respPetUpgradeSucc = new RespPetUpgradeSucc();
        respPetUpgradeSucc.setPetId(pet.getId());
        respPetUpgradeSucc.setBeforeFields(beforeFields);
        respPetUpgradeSucc.setAlterFields(alterFields);

        /**先缓存起来，在对话结束时才显示*/
        role.pushTempCache("pet_fly_success", respPetUpgradeSucc);

        petAttribMonitor.end();
    }

    private void removeTempData(Role role) {
        if (role.getExtendBox() != null) {
            role.getExtendBox().getParams().remove("flying_pet_id");
        }
    }

    private List<FiedValue> getFields(Pet pet) {
        List<FiedValue> fields = new ArrayList<>();
        fields.add(new FiedValue(104, pet.getTotalLifeEffect()));
        fields.add(new FiedValue(105, pet.getTotalManaEffect()));
        fields.add(new FiedValue(106, pet.getTotalSpeedEffect()));
        fields.add(new FiedValue(107, pet.getTotalPhyEffect()));
        fields.add(new FiedValue(108, pet.getTotalMagEffect()));
        return fields;
    }


    @Override
    public void doAfterSubmit(Role role, TaskSet taskSet) {
        super.doAfterSubmit(role, taskSet);

        /**提交后则重置掉*/
        doResetTask(role, taskSet);
    }

    /**放弃任务*/
    public void giveUpTask(Role role) {
        TaskSet taskSet = getTaskSetByType(role);
        giveUpTask(role, taskSet);
    }

    @Override
    public boolean canGiveUpTask(Role role, TaskSet taskSet) {
        return true;
    }

    @Override
    public void doAfterGiveUp(Role role, TaskSet taskSet) {
        role.getTask().addGiveUpTime(getTaskType(), System.currentTimeMillis());
        removeTempData(role);

        super.doAfterGiveUp(role, taskSet);
    }

    /**是否是放弃任务后的等待时间还没到*/
    private boolean isWaitGiveUpCD(Role role) {
        long giveUpTime = role.getTask().getGiveUpTime(getTaskType());
        if (giveUpTime > 0 && (System.currentTimeMillis()-giveUpTime) < TaskDataPool.DELAY_TIME_AFTER_GIVEUP_HELP_PET_FLY) {
            return true;
        }

        return false;
    }

    @Override
    public void doFightMaxRound(Role role, FightEndEvent fightEndEvent) {
        super.doFightMaxRound(role, fightEndEvent);

        fail(role, fightEndEvent);
    }

    /**移除宠物时，检测是否是接了飞升任务的宠物*/
    public void checkWhileRemovePet(Role role, Pet pet) {
        if (role == null || pet == null) {return ;}

        /**移除接了飞升任务宠物*/
        if (role.getExtendBox() != null
                && (Integer)role.getExtendBox().getParams().getOrDefault("flying_pet_id", 0) == pet.getId()) {
            giveUpTask(role);
        }
    }
}
